package com.example.rocketmqdemo.transaction.infr.transactionexecutor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.rocketmqdemo.transaction.domain.gateway.LocalTransactionRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class LocalTransactionRecordRepositoryImpl implements LocalTransactionRecordRepository {

    @Autowired
    private LocalTransactionRecordMapper localTransactionRecordMapper;

    @Override
    public void add(String txId) {
        LocalTransactionRecordDo recordDo = new LocalTransactionRecordDo(txId);
        localTransactionRecordMapper.insert(recordDo);
    }

    @Override
    public boolean exist(String txId) {
        LambdaQueryWrapper<LocalTransactionRecordDo> queryWrapper = Wrappers.lambdaQuery(LocalTransactionRecordDo.class)
                .eq(LocalTransactionRecordDo::getTxId, txId);
        return localTransactionRecordMapper.exists(queryWrapper);
    }
}
